﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MultiDAQ_Analysis.analysis
{
    public abstract class MeasurementParameters
    {
        public abstract string MeasurementType { get; }
        public abstract bool Validate();
    }

    // 各种测量的特定参数类
    public class WorkingSourceParameters : MeasurementParameters
    {
        public override string MeasurementType => "WorkingSourceEfficiency";

        public double GeometryFactor { get; set; } = 0.9;

        // 2π表面发射率 (表面粒子数/min)
        public Dictionary<int, double> AlphaEmissionRates { get; set; } = new Dictionary<int, double>();
        public Dictionary<int, double> BetaEmissionRates { get; set; } = new Dictionary<int, double>();

        public override bool Validate()
        {
            return GeometryFactor > 0 && GeometryFactor <= 1.0 &&
                   AlphaEmissionRates.Values.All(v => v > 0) &&
                   BetaEmissionRates.Values.All(v => v > 0);
        }
    }

    public class StandardSourceParameters : MeasurementParameters
    {
        public override string MeasurementType => "StandardSourceEfficiency";

        public double SampleDiskArea { get; set; } = 1400; // mm²

        // 标准源比活度 Bq/g
        public Dictionary<int, double> AlphaSpecificActivity { get; set; } = new Dictionary<int, double>();
        public Dictionary<int, double> BetaSpecificActivity { get; set; } = new Dictionary<int, double>();

        // 标准源质量 mg
        public Dictionary<int, double> SourceMass { get; set; } = new Dictionary<int, double>();

        public override bool Validate()
        {
            return SampleDiskArea > 0 &&
                   AlphaSpecificActivity.Values.All(v => v > 0) &&
                   BetaSpecificActivity.Values.All(v => v > 0) &&
                   SourceMass.Values.All(v => v > 0);
        }
    }

    public class WaterSampleParameters : MeasurementParameters
    {
        public override string MeasurementType => "WaterSample";

        public double WaterVolume { get; set; } // L (1-99L)
        public double TotalResidueAmount { get; set; } // mg (1-9999mg)  
        public double TestedSampleMass { get; set; } // mg (1-5000mg)
        public bool UseStandardEfficiency { get; set; } = true; // true=标准源效率，false=工作源效率

        public override bool Validate()
        {
            return WaterVolume >= 1 && WaterVolume <= 99 &&
                   TotalResidueAmount >= 1 && TotalResidueAmount <= 9999 &&
                   TestedSampleMass >= 1 && TestedSampleMass <= 5000;
        }
    }

    public class BioSampleParameters : MeasurementParameters
    {
        public override string MeasurementType => "BioSample";

        public double FreshSampleWeight { get; set; } // kg (1-49kg)
        public double TestedSampleMass { get; set; } // mg (1-1000000mg)
        public double TotalAshWeight { get; set; } // mg (1-5000mg)
        public double RecoveryRate { get; set; } = 1.0; // ≤1
        public bool UseStandardEfficiency { get; set; } = true;

        public override bool Validate()
        {
            return FreshSampleWeight >= 1 && FreshSampleWeight <= 49 &&
                   TestedSampleMass >= 1 && TestedSampleMass <= 1000000 &&
                   TotalAshWeight >= 1 && TotalAshWeight <= 5000 &&
                   RecoveryRate > 0 && RecoveryRate <= 1.0;
        }
    }

    public class GasSampleParameters : MeasurementParameters
    {
        public override string MeasurementType => "GasSample";

        public double SamplingVolume { get; set; } // L (1-1000000L)
        public double FilterEfficiency { get; set; } = 1.0; // % (1-100%)，存储时转为小数
        public double AbsorptionFactor { get; set; } = 1.0; // % (1-100%)，存储时转为小数
        public bool UseStandardEfficiency { get; set; } = true;

        public override bool Validate()
        {
            return SamplingVolume >= 1 && SamplingVolume <= 1000000 &&
                   FilterEfficiency > 0 && FilterEfficiency <= 1.0 &&
                   AbsorptionFactor > 0 && AbsorptionFactor <= 1.0;
        }
    }

    public class EnvSampleParameters : MeasurementParameters
    {
        public override string MeasurementType => "EnvSample";

        public double TestedSampleMass { get; set; } // mg (1-5000mg)
        public double CorrectionFactor { get; set; } = 1.0; // 校正系数
        public bool UseStandardEfficiency { get; set; } = true;

        public override bool Validate()
        {
            return TestedSampleMass >= 1 && TestedSampleMass <= 5000 &&
                   CorrectionFactor > 0;
        }
    }
}
